<div class="row">
	<div class="col-md-12">
		<ol class="breadcrumb">
			<li>
				<a href="#" onclick="toHome()">
					主页
				</a>
			</li>
			<li>
				<a href="#" class="toList" onclick="toCounponList()">
					通兑卡列表
				</a>
			</li>
			<li class="active">
				生成优惠券
			</li>
		</ol>
	</div>
</div>
<form role="form" class="form-horizontal">
	<div class="row page-cont">
		<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 cont-top">
			<div class="panel panel-white">
				<div class="panel-heading">
					<h4 class="panel-title">
						<span class="title-text">优惠券录入</span>
					</h4>
					<div class="panel-tools">
						<div class="dropdown">
							<a data-toggle="dropdown" class="btn btn-xs dropdown-toggle btn-transparent-grey">
								<i class="fa fa-cog"></i>
							</a>
							<ul class="dropdown-menu dropdown-light pull-right" role="menu">
								<li>
									<a class="panel-collapse collapses" href="#"><i class="fa fa-angle-up"></i> <span>折叠</span> </a>
								</li>
								<li>
									<a class="panel-expand" href="#">
										<i class="fa fa-expand"></i> <span>全屏</span>
									</a>
								</li>
							</ul>
						</div>
						<a class="btn btn-xs btn-link panel-close" href="#">
							<i class="fa fa-times"></i>
						</a>
					</div>
				</div>
				<div class="panel-body">
					<div class="form-group panel-cont">
					    <label class="col-sm-2 control-label">生成数量</label>
					    <div class="col-sm-5">
					      <input type="text" class="form-control" id="coupon-num" />
					    </div>
					    <span class="col-sm-4 tips">
					    	<i class="fa fa-info-circle"></i>
					    	请输入数字（注：生成优惠券与批量绑定相互独立）
					    </span>
				  	</div>
					<div class="body-cont">
						<div class="newCard">
						  	<div class="form-group panel-cont">
							    <label class="col-sm-2 control-label">通兑卡id</label>
							    <div class="col-sm-5">
							      <input type="text" class="form-control" readonly="readonly" id="card-id" />
							    </div>
						  	</div>
						  	<!-- <div class="form-group panel-cont">
							    <label class="col-sm-2 control-label">是否有规则</label>
							    <div class="col-sm-5">
									<select name="" id="is-rule">
										<option value="无规则">无规则</option>
										<option value="有规则">有规则</option>
									</select>
							    </div>
						  	</div>
						  	<div class="form-group panel-cont prefix-box">
							    <label class="col-sm-2 control-label">请输入前缀</label>
							    <div class="col-sm-5">
									<input type="text" class="form-control" id="prefix" />
							    </div>
								<span class="col-sm-4 tips">
							    	<i class="fa fa-info-circle"></i>
							    	最多四位大写英文字母
							    </span>							    
						  	</div> -->
						</div>						
					</div>
				  	<div class="form-group panel-btn">
				  		<div class="col-sm-2 col-sm-offset-3">
				  			<!-- <button type="button" class="btn btn-green next-btn">下一个</i></button> -->
				  			<button type="button" class="btn btn-danger submit-btn">提交&nbsp;<i class="fa fa-arrow-circle-right"></i></button>
				  		</div>
				  	</div>
				</div>
			</div>
		</div>
	</div>
</form>
<style type="text/css" media="screen">
	.prefix-box{
		display: none;
	}
</style>
<script>
	/**********************************************变量**********************************************/
	var token = MXCookie.get("token",token);  // 登陆token

	/**********************************************事件**********************************************/

	$("#card-id").val($(".pageAdd").attr("data-id"));

	// 提交
	$(".submit-btn").click(function(){
		if($("#coupon-num").val() == ""){
			tips("请输入优惠券数量");
			$("#coupon-num").focus();
		}else{
			createCoupon();
		}
	});	
	/**********************************************函数**********************************************/

	// 生成优惠券
	function createCoupon(){
		$.ajax({
			url: localStorage.grobalUrl + "/discount/getDiscountEXs",
			type:"post",
			data:{
				username: GetQueryString("username"),
				token: token,	
				counponId: $(".pageAdd").attr("data-id"),
				counts: $("#coupon-num").val(),
				prefix: $("#prefix").val()
			},
			success: function(data){
				console.log(data);
				if(data.errCode == "00000"){
					$(".pageAdd").html("");
					getPage("view/coupon/list.html");					
				}else if(data.errCode == "00001"){
					tips(data.errMsg);
				}else if(data.errCode == "00005"){
					tips("请重新登陆");
					setTimeout(function(){
						window.location.href = "login_login.html";
					},500);					
				}else{}
			},
			error: function(error){
				console.log(error);
			}
		})
	}

</script>
